<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加商户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
    <script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="merchantNumber" id="merchantNumber" lay-verify="required" lay-reqtext="用户名不得为空" placeholder="请输入用户名"
                   value="" class="layui-input">
            <input type="hidden" name="merchantFid" id="merchantFid" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">名称</label>
        <div class="layui-input-block">
            <input type="text" name="merchantCheckname" id="merchantCheckname" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="merchantPhone" id="merchantPhone" placeholder="请输入手机号"
                   lay-reqtext="手机号不能为空" value="" class="layui-input" lay-verify="phone">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="password" name="merchantPassword" id="merchantPassword" lay-verify="required"
                   lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">确认密码</label>
        <div class="layui-input-block">
            <input type="password"  placeholder="请输入确认密码" lay-reqtext="确认密码不能为空"
                   lay-verify="required|confirmPass"     value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认提交</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>


<script>
    layui.use(['form'], function () {
        var icon = '';
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            upload = layui.upload;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data.field)
            data.field.file = icon
            $.ajax({
                type: "post",
                url: "../merchant/merchantAdd",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(data.field),
                success: function (result) {
                    if (result.result == "success") {
                        layer.msg("添加商户成功~！！");
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        //parent.$("#shousuobtn",parent.document).trigger('click');	//子页面局部刷新父页面事件
                        window.parent.document.getElementById("shousuobtn").click();
                    }else if (result.result == "error"){
                        layer.msg("添加商户失败~~！！");
                    }
                },
                error: function () {
                    console.log("网络出错！请重新连接")
                }
            });

            return false;
        });

        form.verify({
            confirmPass:function(value){
                if($('input[name=merchantPassword]').val() !== value)
                    return '两次密码输入不一致！';
            }
        });
    });

    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
    $(document).ready(function(){
        var merchantId = getQueryString("merchantId");
        $("#merchantId").val(merchantId);
    });



</script>
</body>
</html>